package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/product"
	"github.com/streadway/amqp"
)

//支付成功, 修改销量和库存
func main() {
	rpcProduct := new(product.Product).Init()
	defer rpcProduct.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("products.log.sales"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("products.queue.sales"), func(msg amqp.Delivery) {
		orderSn := string(msg.Body)
		reply := false
		err := rpcProduct.ChangeProductSalesAndStack(context.Background(), &orderSn, &reply)
		if err != nil {
			utils.Logerr.Printf("订单支付成功，修改销量业务处理任务调用失败，orderSn:%s, err:%s", orderSn, err)
		}
	})

	if err != nil {
		utils.Logerr.Printf("修改产品销量任务错误, err: %s", err.Error())
	}
}
